package br.com.async.core.infrastructure;

import org.hibernate.Criteria;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

import br.com.async.core.domain.customer.Customer;
import br.com.async.core.domain.customer.CustomerRepository;

public class CustomerRepositoryImpl extends AbstractRepositoryImpl<Customer, Integer> implements CustomerRepository{

	public CustomerRepositoryImpl() {
		super(Customer.class);
	}
	
	public Customer findCustomerByPersonCode(Integer personCode){
		
		Criteria criteria = getSession().createCriteria(Customer.class);
		criteria.createAlias("person", "p");
		Criterion c1 = Restrictions.eq("p.code", personCode);
		criteria.add(c1);
		
		return (Customer) criteria.uniqueResult();
	}
	

	
}
